package baseClass;

import baseAPI.Database;

import java.sql.ResultSet;
import java.sql.SQLException;

public class Admin {
    private String userName;
    private String password;
    private int power;

    public Admin(String userName, String password){
        this.userName = userName;
        this.password = password;
    }

    public boolean check(Database database){
        ResultSet resultSet = database.select("password", "admin", "userName = " + "\"" + userName + "\"");
        try{
            if(!resultSet.next()){
                return false;
            }
            return resultSet.getString(1).equals(password);
        }catch (SQLException ex){
            System.out.println("AdminCheckException");
        }
        return false;
    }

    public int getPower(Database database){
        ResultSet resultSet = database.select("power", "admin", "userName = " + userName);
        try{
            if(!resultSet.next()){
                return -1;
            }
            return resultSet.getInt(1);
        }catch (SQLException ex){
            System.out.println("getPowerException");
        }
        return -1;
    }
}
